<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/static/js/jquery-3.2.1.js">
</head>
<body>
<div class="div user-input">
  <input type="number" class="code" name="verify" placeholder="请输入手机验证码">
  <input type="button" class="obtain generate_code" value=" 获取验证码">
</div>
<script type="text/javascript">
  $(function(){

    $(".generate_code").click(function(){
      var disabled = $(".generate_code").attr("disabled");
      if(disabled){ return false;}



      $.ajax({
        type: "GET",
        url: "/register/",
        data: {email:"email"},
        dataType: "json",
        success:function(data){
          console.log(data);
          settime();
        },

      });
    });

    var countdown=60;
    var _generate_code = $(".generate_code");

    function settime() {
      if (countdown == 0) {
        _generate_code.attr("disabled",false);
        _generate_code.val("获取验证码");
        countdown = 60;
        return false;
      } else {
        $(".generate_code").attr("disabled", true);
        _generate_code.val("重新发送(" + countdown + ")");
        countdown--;
      }
      setTimeout(function() {
        settime();
      },1000);
    }

  })

</script>

</body>
</html>